# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

# The 0.8.9 series supports Python 3 but we have an updated version.
# that only supports Python 3.  This is just for Python 2 tools
# and legacy support for the old version.  The devleopers will
# dicontinue support for the 0.x8 on August 31, 2018

_realname=cmd2
pkgbase=mingw-w64-python2-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-python2-${_realname}"
pkgver=0.8.9
pkgrel=1
pkgdesc="Extra features for standard library's cmd module (mingw-w64)"
arch=('any')
url='https://github.com/python-cmd2/cmd2'
license=('MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python2-pyparsing"
         "${MINGW_PACKAGE_PREFIX}-python2-pyperclip"
         "${MINGW_PACKAGE_PREFIX}-python2-colorama"
         "${MINGW_PACKAGE_PREFIX}-python2-contextlib2"
         "${MINGW_PACKAGE_PREFIX}-python2-enum34"
         "${MINGW_PACKAGE_PREFIX}-python2-wcwidth"
         "${MINGW_PACKAGE_PREFIX}-python2-subprocess32")
makedepends=("${MINGW_PACKAGE_PREFIX}-python2-setuptools")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python2-pytest-runner"
#             "${MINGW_PACKAGE_PREFIX}-python2-pytest-xdist" 
              "${MINGW_PACKAGE_PREFIX}-python2-mock")
# 'vi')
options=('staticlibs' 'strip' '!debug')
source=("${_realname}-$pkgver.tar.gz"::"https://github.com/python-cmd2/cmd2/archive/$pkgver.tar.gz")
sha512sums=('1d88e98ced08760f745a426dbf7031e2f8132484e0be833fb7afbbe0b02a0d5416ef7c852dd816cba0329d10356714cfc73fb303bdc885e982223b717d4508cc')

# Helper macros to help make tasks easier #
apply_patch_with_msg() {
  for _patch in "$@"
  do
    msg2 "Applying $_patch"
    patch -Nbp1 -i "${srcdir}/$_patch"
  done
}

del_file_exists() {
  for _fname in "$@"
  do
    if [ -f $_fname ]; then
      rm -rf $_fname
    fi
  done
}
# =========================================== #

prepare() {
  cd "${srcdir}"
  rm -rf python3-build-${CARCH} || true
  cp -r "${_realname}-${pkgver}" "python2-build-${CARCH}"
  # Set version for setuptools_scm
  export SETUPTOOLS_SCM_PRETEND_VERSION=$pkgver
  export PBR_VERSION=$pkgver
}

# Note that build() is sometimes skipped because it's done in 
# the packages setup.py install for simplicity if you can do so.
# but sometimes, you want to do a check before install which would
# also trigger the build.
build() {
    msg "Python 2 build for ${CARCH}"  
    cd "${srcdir}/python2-build-${CARCH}"
    ${MINGW_PREFIX}/bin/python2 setup.py build
}

check() {
  msg "Python 2 test for ${CARCH}"
  cd "${srcdir}/python2-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python2 setup.py pytest || true
}

package() {
  cd "${srcdir}/python2-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python2 setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python2-${_realname}/LICENSE"
}

